﻿/*
 * 描述：     EnumDescriptionAttribute
 */
using System;
using System.Reflection;

public class EnumDescriptionAttribute : Attribute
{
    private string _strDescription;
    public string Description { get { return _strDescription; } }

    public EnumDescriptionAttribute(string strPrinterName)
    {
        _strDescription = strPrinterName;
    }
}

public class EnumUtility
{
    public static string GetDescription(Enum en)
    {
        Type type = en.GetType();
        FieldInfo fieldInfo = type.GetField(en.ToString());
        if (fieldInfo != null)
        {
            object[] attribArray = fieldInfo.GetCustomAttributes(false);
            if (attribArray != null && attribArray.Length > 0)
            {
                return ((EnumDescriptionAttribute)attribArray[0]).Description;
            }
        }
        return en.ToString();
    }
}